2 Copyright (C) 2024 Rubén Beltrán del Río
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see https://map.tranquil.systems.
19 struct SearchBar: View {
21 @Binding var term: String
22 @FocusState var isSearchFocused: Bool
23 var onNext: () -> Void = {}
24 var onPrevious: () -> Void = {}
25 var onSubmit: () -> Void = {}
26 var onDismiss: () -> Void = {}
29 HStack(spacing: 2.0) {
31 TextField("Search", text: $term)
32 .textFieldStyle(.roundedBorder)
33 .padding(.trailing, 16.0)
34 .focused($isSearchFocused)
36 isSearchFocused = true
38 .onKeyPress { press in
39 if press.key == .return {
40 if press.modifiers.contains(.shift) {
51 Button(action: onPrevious) {
52 Image(systemName: "chevron.left")
53 .font(.theme.smallControl)
55 "g", modifiers: EventModifiers([.command, .shift])
56 ).help("Find Previous (⇧⌘G)")
57 Button(action: onNext) {
58 Image(systemName: "chevron.right")
59 .font(.theme.smallControl)
61 "g", modifiers: EventModifiers([.command])
62 ).help("Find Next (⌘G)")
63 Button(action: onDismiss) {
65 .font(.theme.smallControl)
66 }.keyboardShortcut(.escape, modifiers: EventModifiers())
73 SearchBar(term: .constant("Hello"))